package cn.jhc.transport;

import android.os.Handler;
import android.os.Message;

import org.json.JSONException;

import java.io.IOException;
import java.util.TimerTask;

import cn.jhc.transport.bean.Environment;
import cn.jhc.transport.service.TransportService;

/**
 * Created by luyanfei on 16-2-28.
 */
public class UpdateSenseTask extends TimerTask {
    private Handler handler;
    public UpdateSenseTask(Handler handler) {
        this.handler = handler;
    }

    @Override
    public void run() {
        Environment env = null;
        try {
            env = TransportService.getAllSense();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        int co2 = env.getCo2();
        Message co2Message = new Message();
        co2Message.what = EnvType.CO2.ordinal();
        co2Message.arg1 = co2;
        handler.sendMessage(co2Message);
    }
}
